home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gplot386.zip / GNUPLOT.EL < prev    next >
Lisp/Scheme  |  1992-06-06  |  6KB  |  147 lines

  1. ; gnu-plot.el - Definitions of GNU-PLOT mode for emacs editor.
  2. ; Author:    Gershon Elber
  3. ;         Computer Science Dept.
  4. ;         University of Utah
  5. ; Date:    Tue May 14 1991
  6. ; Copyright (c) 1991, 1992, Gershon Elber
  7. ;
  8. ; This file defines an environment to run edit and execute GNU-PLOT programs.
  9. ; Such a program should have a '.gp' extension in order it to be in
  10. ; gnu-plot-mode major mode. Two new functions are provided to communicate
  11. ; between the editted file and the plotting program:
  12. ; 1. send-line-to-gnu-plot - sends a single line to the plotting program for
  13. ;    execution. The line sent is the line the cursor is on,
  14. ;    Bounded to Meta-E by default.
  15. ; 2. send-region-to-gnu-plot - sends the region from the current mark
  16. ;    (mark-marker) to current position (point-marker) to the plotting program.
  17. ;    This function is convenient for sending a large block of commands.
  18. ;    Bounded to Meta-R by default.
  19. ; Both functions checks for existance of a buffer named gnu-plot-program
  20. ; and a process named "gnu-plot" hooked to it, and will restart a new process
  21. ; or buffer if none exists. The program to execute as process "gnu-plot" is
  22. ; defined by the gnu-plot-program constant below.
  23. ;
  24.  
  25. (defvar gnu-plot-program "gnuplot"
  26.   "*The executable to run for gnu-plot-program buffer.")
  27.  
  28. (defvar gnu-plot-echo-program t
  29.   "*Control echo of executed commands to gnu-plot-program buffer.")
  30.  
  31. (defvar gnu-plot-mode-map nil "")
  32. (if gnu-plot-mode-map
  33.     ()
  34.   (setq gnu-plot-mode-map (make-sparse-keymap))
  35.   (define-key gnu-plot-mode-map "\M-e" 'send-line-to-gnu-plot)
  36.   (define-key gnu-plot-mode-map "\M-r" 'send-region-to-gnu-plot))
  37.  
  38. ;;;
  39. ;;; Define the gnu-plot-mode
  40. ;;;
  41. (defun gnu-plot-mode ()
  42.   "Major mode for editing and executing GNU-PLOT files.
  43.  
  44. see send-line-to-gnu-plot and send-region-to-gnu-plot for more."
  45.   (interactive)
  46.   (use-local-map gnu-plot-mode-map)
  47.   (setq major-mode 'gnu-plot-mode)
  48.   (setq mode-name "Gnu-Plot")
  49.   (run-hooks 'gnu-plot-mode-hook))
  50.  
  51. ;;;
  52. ;;; Define send-line-to-gnu-plot - send from current cursor position to next
  53. ;;; semicolin detected.
  54. ;;;
  55. (defun send-line-to-gnu-plot ()
  56.   "Sends one line of code from current buffer to the GNU-PLOT program.
  57.  
  58. Use to execute a line in the GNU-PLOT plotting program. The line sent is
  59. the line the cursor (point) is on.
  60.  
  61. The GNU-PLOT plotting program buffer name is gnu-plot-program and the 
  62. process name is 'gnu-plot'. If none exists, a new one is created.
  63.  
  64. The name of the gnu-plot program program to execute is stored in
  65. gnu-plot-program variable and may be changed."
  66.   (interactive)
  67.   (if (equal major-mode 'gnu-plot-mode)
  68.     (progn
  69.       (make-gnu-plot-buffer)        ; In case we should start a new one.
  70.       (beginning-of-line)
  71.       (let ((start-mark (point-marker)))
  72.     (next-line 1)
  73.     (let* ((crnt-buffer (buffer-name))
  74.            (end-mark (point-marker))
  75.            (string-copy (buffer-substring start-mark end-mark)))
  76.       (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
  77.       (end-of-buffer)
  78.       (if gnu-plot-echo-program
  79.         (insert string-copy))
  80.       (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
  81.       (if (not (pos-visible-in-window-p))
  82.         (recenter 3))
  83.       (switch-to-buffer-other-window (get-buffer crnt-buffer))
  84.       (process-send-region "gnu-plot" start-mark end-mark)
  85.       (goto-char end-mark))))
  86.     (message "Should be invoked in gnu-plot-mode only.")))
  87.  
  88. ;;;
  89. ;;; Define send-region-to-gnu-plot - send from current cursor position to
  90. ;;; current marker.
  91. ;;;
  92. (defun send-region-to-gnu-plot ()
  93.   "Sends a region of code from current buffer to the GNU-PLOT program.
  94.  
  95. When this function is invoked on an GNU-PLOT file it send the region
  96. from current point to current mark to the gnu-plot plotting program.
  97.  
  98. The GNU-PLOT plotting program buffer name is gnu-plot-program and the
  99. process name is 'gnu-plot'. If none exists, a new one is created.
  100.  
  101. The name of the gnu-plot program program to execute is stored in
  102. gnu-plot-program variable and may be changed."
  103.   (interactive)
  104.   (if (equal major-mode 'gnu-plot-mode)
  105.     (progn
  106.       (make-gnu-plot-buffer)     ; In case we should start a new one.
  107.       (copy-region-as-kill (mark-marker) (point-marker))
  108.       (let ((crnt-buffer (buffer-name)))
  109.     (switch-to-buffer-other-window (get-buffer "gnu-plot-program"))
  110.     (end-of-buffer)
  111.     (if gnu-plot-echo-program
  112.       (yank))
  113.     (set-marker (process-mark (get-process "gnu-plot")) (point-marker))
  114.     (if (not (pos-visible-in-window-p))
  115.       (recenter 3))
  116.     (switch-to-buffer-other-window (get-buffer crnt-buffer))
  117.     (process-send-region "gnu-plot" (mark-marker) (point-marker))))
  118.     (message "Should be invoked in gnu-plot-mode only.")))
  119.  
  120. ;;;
  121. ;;; Switch to "gnu-plot-program" buffer if exists. If not, creates one and
  122. ;;; execute the program defined by gnu-plot-program.
  123. ;;;
  124. (defun make-gnu-plot-buffer ()
  125.   "Switch to gnu-plot-program buffer or create one if none exists"
  126.   (interactive)
  127.   (if (get-buffer "gnu-plot-program")
  128.     (if (not (get-process "gnu-plot"))
  129.       (progn
  130.     (message "Starting GNU-PLOT plotting program...")
  131.     (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
  132.     (process-send-string "gnu-plot" "\n")
  133.     (message "Done.")))
  134.     (progn
  135.       (message "Starting GNU-PLOT plotting program...")
  136.       (start-process "gnu-plot" "gnu-plot-program" gnu-plot-program)
  137.       (process-send-string "gnu-plot" "\n")
  138.       (message "Done."))))
  139.  
  140. ;;;
  141. ;;; Autoload gnu-plot-mode on any file with gp extension. 
  142. ;;;
  143. (setq auto-mode-alist (append '(("\\.gp$" . gnu-plot-mode))
  144.                   auto-mode-alist))
  145.